/**
 * @param {number[]} nums
 * @return {number}
 */
var majorityElement1 = function(nums) {
    if(nums.length === 1){
        return nums[0]
    }
    let len = nums.length/2;
    let obj = {};  //对象索引大法，还是某人教我的
    for(let i = 0;i<=nums.length;i++){
    // for(let i = 0;i<Math.ceil(nums.length/2);i++){
        if(obj[nums[i]] !== undefined){
            obj[nums[i]]++;
            if(obj[nums[i]] > len){
                return nums[i]
            }
        }else{
            obj[nums[i]] = 1
        }
        console.log(obj)
    }
    return -1
};

var majorityElement2 = function(nums) {
    nums.sort((a,b)=>{a-b});
    return nums[Math.floor(nums.length/2)]
};
var majorityElement2 = function(nums) {
    nums.sort((a,b)=>{a-b});
    return nums[Math.floor(nums.length/2)]
};